<template>
  <div class="pageWrapper">
    <common-header />
    <div class="content" v-if="content.dataId">
      <div class="card">
        <img v-if="content.avater" class="user" :src="content.avater" />
        <div class="user" v-else>
          {{ nameLastTwoWord }}
        </div>
        <div class="card-content">
          <div class="name">{{ content.userName }}</div>
          <div class="copy">隶属单位：{{content.orgName}}</div>
          <div class="title">{{ content.taskName }}</div>
          <div class="time">{{ content.startTime | timeFormatWithYear }} - {{ content.endTime | timeFormat }}</div>
        </div>
      </div>
      <report-content :content="content" />
    </div>
  </div>
</template>

<script>
import { getReportDetailById, getMonthReportDetailById } from "@/api/report";
import reportContent from "../components/report-content.vue";
import { formatTime } from "@/utils";
export default {
  components: {
    reportContent
  },
  data() {
    return {
      id: 0,
      content: {},
      type: 1
    };
  },
  computed: {
    nameLastTwoWord() {
      return this.content.userName.slice(-2);
    }
  },
  filters: {
    timeFormat(time) {
      return formatTime(time, "MM月dd日");
    },
    timeFormatWithYear(time) {
      return formatTime(time, "yyyy年MM月dd日");
    }
  },
  created() {
    this.id = this.$route.query.id;
    this.type = this.$route.query.type;
    this.initData();
  },
  methods: {
    initData() {
      if (this.type == 1) {
        getReportDetailById(this.id).then(res => {
          this.content = res.data;
        });
      } else {
        getMonthReportDetailById(this.id).then(res => {
          this.content = res.data;
        });
      }
    }
  }
};
</script>

<style scoped lang="scss">
.content {
  padding: 20px 16px;
  .card {
    display: flex;
    background: #fff;
    border-radius: 8px;
    margin-bottom: 16px;
    padding: 16px;
    &:active {
      background: #f9f9f9;
    }
    .card-content {
      flex: 1;
      color: #333;
      font-size: 13px;
      line-height: 18px;
      .name {
        line-height: 20px;
        font-size: 14px;
      }
      .copy {
        color: #a3a7ad;
        font-size: 12px;
        margin-top: 3px;
        margin-bottom: 12px;
      }
      .time {
        color: #a3a7ad;
        margin-top: 6px;
      }
    }
    .user {
      width: 40px;
      height: 40px;
      border-radius: 8px;
      margin-right: 12px;
      background: #2492ff;
      color: #fff;
      text-align: center;
      line-height: 40px;
      font-size: 14px;
    }
  }
}
</style>
